package com.gr.analys;
import com.gr.analys.ViTokenizer;
import java.io.IOException;
import java.io.Reader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;

public final class VietAnalyzer extends Analyzer{
    @Override
    public TokenStream tokenStream(String string, Reader reader) {
            ViTokenizer tokenStream=null;
            try {
        //        System.out.println(">>>>>>>>>>>Creating new _VTokenizer.....");
                tokenStream = new ViTokenizer(reader);
            } catch (Exception ex) {
          //      System.out.println("Loi ko tach tu duoc!");
                ex.printStackTrace();
            }
             setPreviousTokenStream(tokenStream);
            return tokenStream;
    }

  @Override
  public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException {
 //    System.out.println(">>>>>>>>>>>>ReusableTokenStream method.................>>>");
    Tokenizer tokenizer = (Tokenizer) getPreviousTokenStream();
    if (tokenizer == null) {
      tokenizer = new ViTokenizer(reader);
      setPreviousTokenStream(tokenizer);
      //Filter here
      //TODO
    } else
      tokenizer.reset(reader);
    return tokenizer;
  }
   public ViTokenizer reusableTokenStream(Reader reader) throws IOException {
 //    System.out.println(">>>>>>>>>>>>ReusableTokenStream method.................>>>");
    ViTokenizer tokenizer = (ViTokenizer) getPreviousTokenStream();
    if (tokenizer == null) {
      tokenizer = new ViTokenizer(reader);
      setPreviousTokenStream(tokenizer);
      //Filter here
      //TODO
    } else
      tokenizer.reset(reader);
    return tokenizer;
  }
}
